Skip to content

fix: use OpenAI default_headers for Kimi User-Agent#67

Merged
tyrahappy merged 1 commit intomainfrom
fix/kimi-user-agent
Mar 28, 2026
Merged

fix: use OpenAI default_headers for Kimi User-Agent#67
tyrahappy merged 1 commit intomainfrom
fix/kimi-user-agent

Conversation

@0b00101111
Copy link
Copy Markdown
Contributor

Problem

Kimi's API rejects requests without a recognized coding agent User-Agent header (403 access_terminated_error). Our KimiProvider set the header via httpx.Client(headers=...), but the OpenAI SDK overwrites it with its own User-Agent.

Fix

Use default_headers on the OpenAI client instead — these merge into every request without being overwritten.

Verified

Full pipeline run with real Kimi API: 2 videos, 8 API calls, ~19K tokens, 2 personalized results.

Test plan

  • 45 tests pass
  • Real pipeline run succeeds end-to-end

🤖 Generated with Claude Code

The httpx Client headers were being overwritten by the OpenAI SDK's
own User-Agent. Using default_headers on the OpenAI client ensures
the header reaches Kimi's agent whitelist check.

Verified: full pipeline run succeeds with real Kimi API.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 28, 2026 20:09
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the Kimi (Moonshot AI) OpenAI-compatible provider to ensure a required coding-agent User-Agent header survives the OpenAI SDK’s request construction, preventing Kimi 403 access_terminated_error failures.

Changes:

  • Stop using a custom httpx.Client(headers=...) (which gets overridden by the OpenAI SDK’s own headers).
  • Provide User-Agent via the OpenAI client’s default_headers so it’s merged into every request.
  • Move the 120s timeout configuration onto the OpenAI client (timeout=120.0).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@tyrahappy
Copy link
Copy Markdown
Collaborator

LGTM — fix is correct.

The root cause is right: the OpenAI SDK's own middleware sets User-Agent on every request, which overwrites anything set on a wrapped httpx.Client. default_headers on the OpenAI() constructor merges instead of overwriting, so the claude-code/0.1.0 header survives all the way to Kimi's server.

Moving timeout=120.0 from the httpx layer to the OpenAI client directly is also correct — the SDK forwards it to httpx internally.

Removing the httpx import is a nice cleanup since we no longer touch httpx directly.

Good to merge.

@tyrahappy tyrahappy merged commit e13bb2b into main Mar 28, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants